#!/bin/bash
#
#  File      : del
#  Author    : cnscn
#  EMail     : 2003ysy@126.com
#  URL       : http://cnsdel.eliee.com
#  QQ        : 214363570
#  Time      : 2005-08-28 18:00 / 2004-11-30 14:26
#  Copyright : Cnsdel is free software, covered by the GNU General Public License
#              And you are welcome to change it and/or distribute copies of it under certain conditions
#

source  $(dirname $0)/com
source  $(dirname $0)/argsmenufile

if [ $# -eq 0 ] ; then
        echo "Too few arguments"
        echo "del -h for more information"
        exit  1
fi



##########################################################

for i in $*
do
        cd $currpath

        cd $(dirname $i)

        if [ ${i:0:2} = "./" ] ; then

                i=${i:2}

        fi
            
        cd $currpath

        if [ -f $i  -o  -d $i  ] ;  then
                cd $(dirname $i)

                #get the file name  
                pwdir=$(pwd)/$(basename $i)

                tmpname=$(echo $pwdir | tr "/" "=")

                #at home path ,if .trash is not a directory ,then create it
                cd ~
                #if [ ! -d .trash ] ; then
                #        mkdir .trash
                #fi

                #test if the file already exists
                cd ~/.trash
                
                if test -f $tmpname -o -d $tmpname 
                then
                    nowtime=$(date "+%Y%m%d%H%M%S")
 
                    mv -f "${tmpname}" ${tmpname}_${nowtime}
                    echo "$tmpnametmp already exists and rename the old file ${tmpname}_${nowtime}"
                fi

                #change into the current path
                cd $currpath
                mv -f $i  ~/.trash/${tmpname}
                echo "$pwdir is trashed."
        else
                echo "$i: No such file or directory!" 
        fi

done
